
// DataNetSvrView.cpp : implementation of the CDataNetSvrView class
//

#include "stdafx.h"
#include "DataNetSvr.h"

#include "DataNetSvrDoc.h"
#include "DataNetSvrView.h"

#include "ShowPicDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CDataNetSvrView

IMPLEMENT_DYNCREATE(CDataNetSvrView, CView)

BEGIN_MESSAGE_MAP(CDataNetSvrView, CView)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CDataNetSvrView::OnFilePrintPreview)
	ON_WM_SIZE()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_LBUTTONDBLCLK()
	ON_WM_MOUSEHWHEEL()
	ON_WM_CREATE()
	ON_WM_MOUSEMOVE()
	ON_WM_RBUTTONDBLCLK()
	ON_WM_MOUSEWHEEL()
	ON_COMMAND(ID_HELP_SHOWPIC, &CDataNetSvrView::OnShowPicDlg)
END_MESSAGE_MAP()

// CDataNetSvrView construction/destruction

CDataNetSvrView::CDataNetSvrView()
{
	// TODO: add construction code here

}

CDataNetSvrView::~CDataNetSvrView()
{
}

BOOL CDataNetSvrView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

// CDataNetSvrView drawing

void CDataNetSvrView::OnDraw(CDC* pDC)
{
	CDataNetSvrDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: add draw code for native data here
	m_oMap.Draw(pDC);
}


// CDataNetSvrView printing


void CDataNetSvrView::OnFilePrintPreview()
{
	AFXPrintPreview(this);
}

BOOL CDataNetSvrView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CDataNetSvrView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CDataNetSvrView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CDataNetSvrView::OnRButtonUp(UINT nFlags, CPoint point)
{
	ClientToScreen(&point);
	OnContextMenu(this, point);
}

void CDataNetSvrView::OnContextMenu(CWnd* pWnd, CPoint point)
{
	theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
}


// CDataNetSvrView diagnostics

#ifdef _DEBUG
void CDataNetSvrView::AssertValid() const
{
	CView::AssertValid();
}

void CDataNetSvrView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CDataNetSvrDoc* CDataNetSvrView::GetDocument() const // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDataNetSvrDoc)));
	return (CDataNetSvrDoc*)m_pDocument;
}
#endif //_DEBUG


// CDataNetSvrView message handlers

//BOOL CDataNetSvrView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
//{
//	// TODO: Add your specialized code here and/or call the base class
//
//	return CView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
//}

void CDataNetSvrView::OnSize(UINT nType, int cx, int cy)
{
	CView::OnSize(nType, cx, cy);

	// TODO: Add your message handler code here
	CSize sz(cx, cy);
	m_oMap.UpdateSize(&sz);
}

void CDataNetSvrView::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	SetCursor(LoadCursor(NULL, IDC_APPSTARTING ));//IDC_WAIT
	//UpdateWindow();
	//ReleaseCapture();

	m_oMap.BeginMove(&point);
	this->SetCapture();

	CView::OnLButtonDown(nFlags, point);
}

void CDataNetSvrView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	m_oMap.BeginMove(&point);
	//this->SetCapture();

	CView::OnLButtonDblClk(nFlags, point);
}

void CDataNetSvrView::OnLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	
	

	m_oMap.EndMove(&point);
	ReleaseCapture();
	Invalidate(false);

	CView::OnLButtonUp(nFlags, point);
}


void CDataNetSvrView::OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt)
{
	// This feature requires Windows Vista or greater.
	// The symbol _WIN32_WINNT must be >= 0x0600.
	// TODO: Add your message handler code here and/or call default

	// HCURSOR hCur  =  LoadCursor( NULL  , IDC_WAIT   ) ; 
     //::SetCursor(hCur);

	return CView::OnMouseHWheel(nFlags, zDelta, pt);
}

int CDataNetSvrView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here

		// TODO: Add your specialized creation code here
	m_oMap.LoadMapFromPicture(_T("sz.bmp"));
	m_oMap.CreateNavigate(GetSafeHwnd());

	return 0;
}

void CDataNetSvrView::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default
	// IDC_CROSS 
	// IDC_ARROW

	 //HCURSOR hCur  =  LoadCursor( NULL  , IDC_IBEAM   ) ; 
     //::SetCursor(hCur);

	//SetCursor(LoadCursor(NULL, IDC_WAIT ));//IDC_WAIT

	CView::OnMouseMove(nFlags, point);
}

void CDataNetSvrView::OnRButtonDblClk(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	HCURSOR hCur  =  LoadCursor( NULL  , IDC_CROSS   ) ; 
      ::SetCursor(hCur);

	CView::OnRButtonDblClk(nFlags, point);
}

BOOL CDataNetSvrView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
	// TODO: Add your message handler code here and/or call default

	if (zDelta > 0)
	{
		m_oMap.ZoomOut();
	}
	else
	{
		m_oMap.ZoomIn();
	}

	this->Invalidate(false);
	return CView::OnMouseWheel(nFlags, zDelta, pt);
}

void CDataNetSvrView::OnShowPicDlg()
{
	// TODO: Add your command handler code here
	// MessageBox(_T("CDataNetSvrView::OnShowPicDlg"));

	CShowPicDlg dlg;

	if(IDOK == dlg.DoModal())
	{
	}else
	{
	}

}
